package com.example.leetcode;

public class KeyWord {
    public static String word(String s){
        if (s==null||s.trim().length()==0){
            return "";
        }
        String[] str = s.trim().split(" ");
        StringBuffer stringBuffer= new StringBuffer();
        for (int i=str.length-1;i>=0;i--){
            if (str[i].trim().equals(" ")){
                continue;
            }
            stringBuffer.append(str[i].trim()+" ");
        }
        return stringBuffer.toString().trim();
    }

    public static void main(String[] args) {
        String s= "let we are";
        System.out.println(words(s));
    }

    public static String words(String s){
        if (s==null||s.trim().length()==0){
            return "";
        }
        String[] str = s.trim().split(" ");
        StringBuffer stringBuffer= new StringBuffer();
        for (int i=str.length-1;i>=0;i--){
            if (str[i].trim().equals(" ")){
                continue;
            }
            stringBuffer.append(resverOder(str[i].trim())+" ");
        }
        return stringBuffer.toString().trim();
    }

    private static String resverOder(String s) {
        String s1="";
        for (int i=s.length()-1;i>=0;i--){
            //记住s.charAt(i); todo
            s1+=String.valueOf(s.charAt(i));
        }
            return s1;
    }


}
